package proxytracing; /**
 * Performs the forwarding of the method invocation
 * inside of a synchronized block where the lock of real target
 * is used.
 */
//start extract SynchronizedIH
import java.lang.reflect.*;

public class SynchronizedIH extends InvocationHandlerBase {

    private static final boolean test = false;
    
    public static Object createProxy( Object obj ) {
	return Proxy.newProxyInstance( obj.getClass().getClassLoader(),
				       obj.getClass().getInterfaces(),
				       new SynchronizedIH( obj ) );
    }
    
    private SynchronizedIH( Object obj ) { super( obj ); }
    
    public Object invoke( Object proxy, Method method, Object[] args ) 
	throws Throwable 
    {
	Object result = null;
	synchronized ( this.getRealTarget() ) {
	    if (test)
		System.out.println( "Synchronizing..." );

	    result = method.invoke( nextTarget, args );

	    if (test)
		System.out.println( "... synchronizing completed" );
	}
	return result;
    }
}
//stop extract SynchronizedIH
